#include "trap.h"
#include "ysyxsoc.h"
#include "riscv.h"
#define ARRSIZE 512

void unalign_test (size_t addr_base,size_t len){
    for (size_t i = addr_base; i < addr_base+len; i=i+7)
    {
        outb(i,   (uint8_t) (i     & 0x00000000ff));   
        outw(i+1, (uint16_t)((i+1) & 0x000000ffff)); 
        outl(i+3, (uint32_t)((i+3) & 0x00ffffffff));
        check(inb(i) == (uint8_t)(i & 0x00000000ff));
        check(inw(i + 1) == (uint16_t)((i + 1) & 0x000000ffff));
        check(inl(i + 3) == (uint32_t)((i + 3) & 0x00ffffffff));
    }    
    for (size_t i = addr_base; i < addr_base+len; i=i+7)
    {
        check(inb(i)   == (uint8_t) (i & 0x00000000ff));
        check(inw(i+1) == (uint16_t)((i+1) & 0x000000ffff));  
        check(inl(i+3) == (uint32_t)((i+3) & 0x00ffffffff));            
    }        
}
int main() {
    int a[ARRSIZE];

//    unalign_test(a[0], 0x128);

    for (int i = 0; i < ARRSIZE; i++)
    {
        a[i] =  0xffff0f0f;
    }
    for(int i=0;i<ARRSIZE;i++) {
        check(a[i] == (0xffff0f0f));
    }
    return 0;
}